define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_getinfo(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"agenterdemand":[{"info_id":"001","brand_id":"001","brand_name":"世达","cat_type":[{"id":"001","name":"品类_001"},{"id":"002","name":"品类_002"}],"region":[{"id":"001","name":"上海"},{"id":"002","name":"北京"}],"num":20,"hasnum":2,"surplus":18,"store":[{"id":"001","name":"店铺_001","apply_time":"2017/01/01 09:00:00","status":"通过"},{"id":"002","name":"店铺_002","apply_time":"2017/01/02 09:00:00","status":"审核中"}]},{"brand_id":"002","brand_name":"博士","cat_type":[{"id":"001","name":"品类_001"},{"id":"002","name":"品类_002"}],"region":[{"id":"001","name":"上海"},{"id":"002","name":"北京"}],"num":20,"hasnum":2,"surplus":18,"store":[{"id":"001","name":"店铺_001","apply_time":"2017/01/01 09:00:00","status":"通过"},{"id":"002","name":"店铺_002","apply_time":"2017/01/02 09:00:00","status":"审核中"}]}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}

		}
		
		function get_data_agenterdemandEdit(result) {
			if(false) {
				 result = '{"success": true,"msg": "","result":'+
				'{"info_id": "001"},'+
				'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}

		}

		//返回信息
		return {
			getinfo: function(info_id,callback) {
				//post请求
				Http.post({
						method: 'member.agenterdemand.getlist',
						info_id:info_id

					},
					function(result) {
						//函数回调
						if(callback)
						callback(get_data_getinfo(result).success);

					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//寻找代理商
			distributordemand_edit: function(info_id,brand_id,cat_type,region,requirement,num,phone,callback) {
				var updateParams = new Object();
				updateParams.info_id = info_id;
				updateParams.brand_id = brand_id;
				updateParams.cat_type = cat_type;
				updateParams.region = region;
				updateParams.requirement = requirement;
				updateParams.num = num;
				updateParams.phone = phone;
				updateParams = JSON.stringify(updateParams);
				//post请求
				Http.post({
						method: 'member.agenterdemand.edit',
						updateParams: updateParams

					},
					function(result) {
						//函数回调
						if(callback)
						callback(get_data_agenterdemandEdit(result));

					},

					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//可选品牌
			brand_list: function(callback) {
				Http.post({
					method: 'member.brand.getlist'
				},
				function(result) {
					//请求成功
					if(callback)
						callback(result.result);
				},
				function(e) {
					//请求异常
				},
				function() {
					//请求完成，一般不做什么事情
				});
			},
			distributor_detail:function(info_id,callback){
				Http.post({
					method:'member.agenterdemand.detail',
					info_id:info_id
				},function(result){
					if(callback)
					callback(result.result);
				},function(){
					
				},function(){
					
				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Distributor_publish", factory);
});